import 'package:flutter_admin/pages/common/cry/cry_all.dart';
import 'package:flutter_admin/pages/common/cry/vo/select_option_vo.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_admin/pages/common/cry/cry_button.dart';
import 'package:flutter_admin/api/odoo/dynamic_data_api.dart';
import 'package:flutter_admin/constants/constant.dart';
import 'package:flutter_admin/models/odoo/dms_documenttype.dart';
import 'package:flutter_admin/utils/store_util.dart';
import '../../../generated/l10n.dart';

class SelectDocumenttypeDialog extends StatefulWidget {
  SelectDocumenttypeDialog();

  @override
  _SelectDocumenttypeDialogState createState() => _SelectDocumenttypeDialogState();
}

class _SelectDocumenttypeDialogState extends State<SelectDocumenttypeDialog> {

  // late List<Widget> children;
  final GlobalKey<FormState> formKey = GlobalKey<FormState>();

  DmsDocumenttype  dmsDocumenttype = DmsDocumenttype();

  List<SelectOptionVO> departmentList = [];

  @override
  void initState() {
    var deparment =
    StoreUtil.read(Constant.KEY_CURRENT_USER_INFO)[0]["department_id"];
    dmsDocumenttype.departmentId = deparment[0].toString();
    dmsDocumenttype.departmentName = deparment[1].toString();
    super.initState();
    _loadData();
  }

  _loadData() async{
    departmentList = await DynamicDataApi.getModelSelect(
      model: "hr.department",
      name: "complete_name",
    );
    setState(() { });
  }
  @override
  Widget build(BuildContext context) {
    var form = Form(
      key: formKey,
      child: Wrap(
        children: <Widget>[
          CrySelect(
            label: '部门',
            dataList: departmentList,
            value: dmsDocumenttype.departmentId,
            onSaved: (v) {
              dmsDocumenttype.departmentId = v;
            },
          ),
          CryInput(
            label: '档案项目名称',
            value: dmsDocumenttype.documenttypename,
            onSaved: (v) {
              dmsDocumenttype.documenttypename = v;
            },
          ),

        ],
      ),
    );
    var buttonBar = ButtonBar(
      alignment: MainAxisAlignment.center,
      children: <Widget>[
        CryButton(
          label: "确定",
          onPressed: () {
            FormState form = formKey.currentState!;
            form.save();
            Navigator.pop(context, dmsDocumenttype);
          },
          iconData: Icons.save,
        ),
        CryButton(
          label: S.of(context).cancel,
          onPressed: () {
            Navigator.pop(context);
          },
          iconData: Icons.cancel,
        )
      ],
    );
    var result = Scaffold(
      appBar: AppBar(
        title: Text("查询"),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [form],
        ),
      ),
      bottomNavigationBar: buttonBar,
    );
    return SizedBox(
      width: 650,
      height: 650,
      child: result,
    );
    // return result;
  }
}